﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class OnlyAuthenticated_EditAbrevieri : System.Web.UI.Page
{
    String currentUser;
    String selectedItems;
    SqlConnection connection = new SqlConnection("Server=27424b2d-be0f-46c5-b105-a1ab015ef95f.sqlserver.sequelizer.com;Database=db27424b2dbe0f46c5b105a1ab015ef95f;User ID=flvirntmiujloika;Password=wVBm2uXivJGURbWJuu7sJZJEpKRsuhbTDCJbPovZKR8g7aTsbUgnwhyEm65qKDWn;");
   
    protected void Page_Load(object sender, EventArgs e)
    {
        currentUser = LoginName.Page.User.Identity.Name;
        currentUserTextBox.Text = currentUser;
		GenreHiddenTextArea.Value = MFRadioButtonList.SelectedItem.Text;
    
    }


    protected void InsertButton_Click(object sender, EventArgs e)
    {
        String startTag="", endTag="";

        if (DropDownListMarimeText.SelectedValue != null) { 
            startTag = "<font size='" + DropDownListMarimeText.SelectedValue + "'>";
            endTag = "</font>";
        }

        if (CheckBoxBold.Checked) {
            startTag += "<b>";
            endTag += "</b>";
        }

        if (CheckBoxItalic.Checked)
        {
            startTag += "<i>";
            endTag += "</i>";
        }

        if ((TextBox1.Text != "") & (!TextBox1.Text.EndsWith(" ")) & (!TextBox1.Text.StartsWith(" ")) & (TextBox2.Text != ""))
        {

            InsertRecord(TextBox1.Text, TextBox2.Text, DropDownListSpecialitate.SelectedValue,
                CheckBoxBold.Checked, CheckBoxItalic.Checked, DropDownListMarimeText.SelectedValue, MFRadioButtonList.SelectedValue, currentUser);

        }

        TextBox1.Text = "";
        TextBox2.Text = "";
        DropDownList1.DataBind(); //force refresh

    }



    private void InsertRecord(String abreviere, String textAbreviere, String numeSpecialitate, Boolean bold, Boolean italic, String marimeText, String gen, String currentUser1)
    {

        string sqlStatement = "INSERT INTO Abrevieri (Abreviere, TextAbreviere, Specialitate, Bold, Italic, MarimeText, Gen, UserEditor) VALUES (@abreviere, @textAbreviere, @numeSpecialitate, @bold, @italic, @marimeText, @gen, @currentUser1)";

        try
        {
            connection.Open();
            SqlCommand cmd = new SqlCommand(sqlStatement, connection);
            cmd.Parameters.AddWithValue("@Abreviere", abreviere);
            cmd.Parameters.AddWithValue("@TextAbreviere", textAbreviere);
            cmd.Parameters.AddWithValue("@NumeSpecialitate", numeSpecialitate);
            cmd.Parameters.AddWithValue("@Bold", bold);
            cmd.Parameters.AddWithValue("@Italic", italic);
           // cmd.Parameters.AddWithValue("@StartTag", startTag);
           // cmd.Parameters.AddWithValue("@EndTag", endTag);
            cmd.Parameters.AddWithValue("@MarimeText", marimeText);
            cmd.Parameters.AddWithValue("@Gen", gen);
            cmd.Parameters.AddWithValue("@currentUser1", currentUser1);
            //cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Deletion/Insertion Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            connection.Close();
        }

    }

	protected void MFRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
	{
		GenreHiddenTextArea.Value = MFRadioButtonList.SelectedItem.Text;
	}
}